package com.changgou.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author Jiang Yilin
 * @title: SysDataUtil
 * @projectName changgou_parent
 * @description: TODO
 * @date 2020/3/618:23
 */
@Component
public class SysDataUtil {

    @Autowired
    RedisTemplate redisTemplate;

    public String getDictLable(String type,String value){
        Object o = redisTemplate.opsForHash().get(type, value);
        if(o==null){
            return value;
        }
        String result = String.valueOf(o);
        return result;
    }

    public List getDictLables(String type){
        Map<String,String> entries = redisTemplate.opsForHash().entries(type);
        if(entries==null){
            return new ArrayList();
        }
        return (List) entries.values();
    }

    public Set getDictValues(String type){
        Map entries = redisTemplate.opsForHash().entries(type);
        if(entries==null){
            return new HashSet();
        }
        return entries.keySet();
    }
}
